package week_11;

public class DoubleSideBubble {

    public static void sort(Comparable[] a) {
        int l = a.length;
        for (int i = 0; i < a.length/2; i++) {
            for (int j = i + 1; j < a.length; j++) {
                if (greater(a[i], a[j])) {
                    exch(a, i, j);
                }
            }
            for (int k = i+1; k < a.length-1; k++) {
                if (greater(a[l-k-2], a[l-i-1])) {
                    exch(a, l-k-2, l-i-1);
                }
            }
        }

    }

    public static boolean greater(Comparable v, Comparable w) {
        return v.compareTo(w) > 0;
    }

    public static void exch(Comparable[] a, int i, int j) {
        Comparable temp;
        temp = a[i];
        a[i] = a[j];
        a[j] = temp;
    }
}
